package com.charles.video.system.controller;

import com.charles.video.api.domain.Banner;
import com.charles.video.common.core.controller.BaseController;
import com.charles.video.common.core.responseDomain.AjaxResult;
import com.charles.video.system.mapper.BannerInfoMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Charles-H
 * 
 * 轮播图控制层
 */
@RestController
@RequestMapping("/banner")
public class BannerController extends BaseController {

    @Resource
    private BannerInfoMapper bannerInfoMapper;

    @GetMapping("/getBannerList")
    public AjaxResult getBannerList() {
        return AjaxResult.success(bannerInfoMapper.queryAllBannerList());
    }
    
    @GetMapping("/getBanner/{bannerId}")
    public AjaxResult getBanner(@PathVariable("bannerId") Integer bannerId) {
        return AjaxResult.success(bannerInfoMapper.queryBannerByBid(bannerId));
    }

    @PostMapping("/addBanner")
    public AjaxResult addBanner(@RequestBody Banner banner) {
        return toAjax(bannerInfoMapper.insertBannerInfo(banner));
    }

    @PutMapping("/updateBanner")
    public AjaxResult updateBanner(@RequestBody Banner banner) {
        return toAjax(bannerInfoMapper.updateBannerInfo(banner));
    }

    @DeleteMapping("/deleteBanner/{bannerId}")
    public AjaxResult deleteBanner(@PathVariable("bannerId") Integer bannerId) {
        return toAjax(bannerInfoMapper.deleteBannerInfoByBid(bannerId));
    }

}
